package io.github.maojian.bianrysearch;

import org.junit.Test;

/**
 * @Auther: jian.mao
 * @Date: 2022-06-24 11:27
 * @Description: https://leetcode.cn/problems/find-smallest-letter-greater-than-target/
 */
public class Q744 {
    public char nextGreatestLetter(char[] letters, char target) {
        int length = letters.length;
        if (target >= letters[length - 1]) {
            return letters[0];
        }
        int left = 0, right = length - 1;
        while (left < right) {
            int mid = (right - left) / 2 + left;
            if (letters[mid] > target) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return letters[left];
    }

    @Test
    public void test() {
        char[] letters = new char[]{};
        char target = 'a';
        System.out.println(nextGreatestLetter(letters, target));
    }
}
